home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJLSR200.ZIP / src / libc / ansi / stdlib / exit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-29  |  816 b   |  37 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <stdlib.h>
  4. #include <unistd.h>
  5. #include <fcntl.h>
  6. #include <dos.h>
  7. #include <io.h>
  8. #include <libc/atexit.h>
  9.  
  10. struct __atexit *__atexit_ptr = 0;
  11.  
  12. void (*__stdio_cleanup_hook)(void);
  13.  
  14. typedef void (*FUNC)(void);
  15. extern FUNC djgpp_first_dtor[] __asm__("djgpp_first_dtor");
  16. extern FUNC djgpp_last_dtor[] __asm__("djgpp_last_dtor");
  17.  
  18. void
  19. exit(int status)
  20. {
  21.   int i;
  22.   struct __atexit *a = __atexit_ptr;
  23.   while (a)
  24.   {
  25.     (a->__function)();
  26.     a = a->__next;
  27.   }
  28.   if (__stdio_cleanup_hook)
  29.     __stdio_cleanup_hook();
  30.   for (i=0; i<djgpp_last_dtor-djgpp_first_dtor; i++)
  31.     djgpp_first_dtor[i]();
  32.  
  33.   /* in case the program set it this way */
  34.   setmode(0, O_TEXT);
  35.   _exit(status);
  36. }
  37.